/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.os.dao.zakharov.oracle;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Collection;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Zakharov
 */
@Entity
@Table(name = "USERS")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Users.findAll", query = "SELECT u FROM Users u"),
    @NamedQuery(name = "Users.findByIdUser", query = "SELECT u FROM Users u WHERE u.idUser = :idUser"),
    @NamedQuery(name = "Users.findByLogin", query = "SELECT u FROM Users u WHERE u.login = :login"),
    @NamedQuery(name = "Users.findByPassword", query = "SELECT u FROM Users u WHERE u.password = :password")})
public class Users implements Serializable {
    
    private static final long serialVersionUID = 1L;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Id
    @Basic(optional = false)
    @NotNull
    @Column(name = "ID_USER")
    private BigDecimal idUser;
    
    @Size(max = 30)
    @Column(name = "LOGIN")
    private String login;
    
    @Size(max = 30)
    @Column(name = "PASSWORD")
    private String password;
    
    @JoinColumn(name = "ID_REGISTRATION", referencedColumnName = "ID_REGISTRATION")
    @ManyToOne
    private Registration idRegistration;
    
    //@Column(name = "ID_REGISTRATION")
    //private BigDecimal idUserRegistration;
    
    @OneToMany(mappedBy = "idUser")
    private Collection<Application> applicationCollection;

    public Users() {
    }

    public Users(BigDecimal idUser) {
        this.idUser = idUser;
    }

    public BigDecimal getIdUser() {
        return idUser;
    }

    public void setIdUser(BigDecimal idUser) {
        this.idUser = idUser;
    }

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Registration getIdRegistration() {
        return idRegistration;
    }

    public void setIdRegistration(Registration idRegistration) {
        this.idRegistration = idRegistration;
    }

    @XmlTransient
    public Collection<Application> getApplicationCollection() {
        return applicationCollection;
    }

    public void setApplicationCollection(Collection<Application> applicationCollection) {
        this.applicationCollection = applicationCollection;
    }

    /*public BigDecimal getIdUserRegistration() {
        return idUserRegistration;
    }

    public void setIdUserRegistration(BigDecimal idUserRegistration) {
        this.idUserRegistration = idUserRegistration;
    }*/
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idUser != null ? idUser.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Users)) {
            return false;
        }
        Users other = (Users) object;
        if ((this.idUser == null && other.idUser != null) || (this.idUser != null && !this.idUser.equals(other.idUser))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "edu.os.dao.zakharov.oracle.Users[ idUser=" + idUser + " ]";
    }
    
}
